#include "Power5Buff.h"
#include "StateBar.h"
#include "PowerMaxBuff.h"


Power5Buff::Power5Buff(void)
{
	_weaponLvlBackup = 0;
}


Power5Buff::~Power5Buff(void)
{
}

void Power5Buff::onStart(StateBar* stateBar)
{
	// Check if exist Power 5
	//bool isExit = false;
	CCArray* listBuff = stateBar->getBuffs();
	CCObject* it;
	CCARRAY_FOREACH(listBuff, it)
	{
		PowerMaxBuff* buff5 = dynamic_cast<PowerMaxBuff*>(it);
		if (buff5)
		{
			stateBar->removeBuff(this, false);
			return;
		}
	}


	_weaponLvlBackup = getPlane()->getWeaponLevel();
	getPlane()->setWeaponLevel(_weaponLvlBackup + 5);
}

void Power5Buff::onComplete()
{
	getPlane()->setWeaponLevel(_weaponLvlBackup);
}

bool Power5Buff::init()
{
	if (!BaseBuff::init())
		return false;

	CCSprite* sprite = CCSprite::createWithSpriteFrameName("power_5_icon.png");
	sprite->setAnchorPoint(ccp(0.5f, 0.5f));
	sprite->setPosition(ccp(getBlackMask()->boundingBox().getMidX(), getBlackMask()->boundingBox().getMidY()));
	addChild(sprite, 0);

	getBlackMask()->setScaleY(1.0f);

	return true;
}
